﻿using System;
using QzEbook.Common;
using System.Data.Common;
using System.Data;
using System.Collections.Generic;
namespace QzEbook.AccessObject
{
    public class Favorite : abstractAccess<Favorite>
    {
        private int bookId;

        public int BookId
        {
            get { return bookId; }
            set { bookId = value; }
        }
        private int userId;

        public int UserId
        {
            get { return userId; }
            set { userId = value; }
        }
        private int type = 0;

        public Favorite()
        {
        }

        /// <summary>
        /// 只取Bookid;
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        protected override Favorite bindRow(System.Data.DataRow row)
        {
            Favorite favorite = new Favorite();
            favorite.bookId =(Int32)row["BID"];
            return favorite;
        }

        protected override System.Data.DataTable selectTable()
        {
            throw new NotImplementedException();
        }

        public List<Favorite> selectUserFavoriteBookIdList()
        {
            return this.bindTable(this.selectUser());
        }



        protected override void bindDefaultParameter(DbCommand command)
        {
            addParameter(command, "@BID", BookId);
            addParameter(command, "@UID", UserId);
            addParameter(command, "@Type", type);
        }

        public DataTable selectUser()
        {
            DbCommand command = CreateCommand("SelectUserFavorite");
            addParameter(command, "@UID", UserId);
            return DataAccess.ExcuteSelectCommand(command);
        }

        public override bool insert()
        {
           type = 1;
            DbCommand command=CreateCommand("FavoriteAction");
            bindDefaultParameter(command);
            return DataAccess.ExecuteNonQuery(command)>0;
        }
        public override bool delete()
        {
            type = 0;
            DbCommand command = CreateCommand("FavoriteAction");
            bindDefaultParameter(command);
            return DataAccess.ExecuteNonQuery(command) > 0;
        }
    }
}